package com.incidentallyhelp.incidentallyhelp;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.RequestMessage;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ListViewSimpleAdapter extends SimpleAdapter implements Serializable {
	
	/**
	 * 
	 */

	private ListView listView;
	
	private List<Map<String, String>> data = null;
	//private static int resource = R.layout.item_of_listview_for_accept;
	private static String[] from = new String[]{"title", "describe", "time"};//TODO
	private static int[] to = new int[]{R.id.textViewTitle, R.id.textViewDescribe, R.id.textViewTime};

	public ListViewSimpleAdapter(Context context, List<Map<String, String>> data, int resource,
			ListView listView
			) {
		super(context, data, resource, from, to);
		this.data = data;
		this.listView = listView;
		// TODO Auto-generated constructor stub
	}

	public boolean addItem(RequestMessage requestMessage) {
		Map<String, String> map = new HashMap<String, String>();
			map.put("title", requestMessage.getTitle());
			map.put("describe", requestMessage.getDescribe());
			map.put("time", requestMessage.getTime());
		data.add(map);
		listView.setAdapter(this);
		return true;
	}
	public boolean deleteItem(RequestMessage requestMessage) {
		for (int i = 0; i < data.size(); i++) {
			Map<String, String> map = data.get(i);
			if (map.get("title") == requestMessage.getTitle()) {
				data.remove(map);
			}
			listView.setAdapter(this);
		}
		return true;
	}
}
